#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5;
const int oo = LONG_MIN;
int tong[N];
struct node{
    int v, sl, gj;
} a[N];

signed main(){
    freopen("duel.in", "r", stdin);
    freopen("duel.out", "w", stdout);
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++){
        int x;
        scanf("%lld", &x);
        tong[x] ++;
    }
    int cnt = 0;
    for(int i = 1; i <= 100000; i ++){
        if(tong[i] != 0){
            a[cnt].v = i;
            a[cnt].gj = tong[i];
            a[cnt ++].sl = tong[i];
            //a[cnt ++].sysl = tong[i];
        }
    }
    int ans = 0;
    for(int i = 0; i < cnt; i ++){
        if(a[i + 1].gj >= a[i].sl){
            a[i + 1].gj -= a[i].sl;
            a[i].sl = 0;
            a[i].gj = 0;
        }
        else{
            if(a[i + 1].gj - (a[i].sl - a[i].gj) > 0) a[i].gj -= a[i + 1].gj - (a[i].sl - a[i].gj);
            a[i].sl -= a[i + 1].gj;
            a[i + 1].gj = 0;
        }
    }
    int last_max = oo;
    int ans2 = 0;
    for(int i = 0; i < cnt; i ++){
        ans += a[i].sl;
        ans2 += a[i].sl;
        //cout << a[i].sl << ' ' << a[i].gj << endl;
        if(a[i].gj >= 0 && last_max != oo){
            if(a[i].gj > last_max){
                ans -= last_max;
                a[i].gj -= last_max;
                last_max = 0;
            }
            else{
                ans -= a[i].gj;
                last_max -= a[i].gj;
            }
        }
        if(last_max == oo) last_max = max(last_max, a[i].sl);
        else last_max += a[i].sl;
    }
    cout << ans;
    fclose(stdin);
    fclose(stdout);
    return 0;
}
/*
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5;
const int oo = 0x7fffffffffffffff;
int tong[N];
struct node{
    int v, sl, gj;
} a[N], b[N], c[N];
signed main(){
    freopen("duel4.in", "r", stdin);
    freopen("duel.out", "w", stdout);
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++){
        int x;
        cin >> x;
        tong[x] ++;
    }
    int cnt = 0;
    for(int i = 1; i <= 100000; i ++){
        if(tong[i] != 0){
            a[cnt].v = i;
            a[cnt].gj = tong[i];
            a[cnt ++].sl = tong[i];
            //a[cnt ++].sysl = tong[i];
        }
    }
    int ans = 0, tmp = 0;
    for(int i = 0; i < cnt; i ++){
        if(a[i + 1].gj >= a[i].sl){
            a[i + 1].gj -= a[i].sl;
            a[i].sl = 0;
            a[i].gj = 0;
        }
        else{
            a[i].sl -= a[i + 1].gj;
            //if(a[i].sl < a[i].gj) a[i].gj -= a[i + 1].gj - a[i].sl;
            a[i].gj -= a[i + 1].gj;
            a[i + 1].gj = 0;
            b[tmp].sl = a[i].sl;
            b[tmp].v = a[i].v;
            b[tmp ++].gj = a[i].gj;
        }
    }

    int last_max = -oo;
    for(int i = 0; i < cnt; i ++){
        ans += a[i].sl;
        cout << a[i].sl << ' ' << a[i].gj << endl;
        if(a[i].gj >= 0 && last_max != -oo){
            if(a[i].gj > last_max) ans -= last_max;
            else ans -= a[i].gj;
            last_max -= a[i].gj;
        }
        last_max = max(last_max, a[i].sl);
    }
    cout << ans;
    fclose(stdin);
    fclose(stdout);
    return 0;
}
*/
